package model;

/**
 * Created with IntelliJ IDEA.
 * User: Student
 * Date: 30/11/12
 * Time: 09:36
 * To change this template use File | Settings | File Templates.
 */
public class WorkTask implements Task {

    private Integer unitsOfWork;
    private Integer unitsOfWorkDone;

    public WorkTask(int estimatedUnitsOfWork) {
        unitsOfWork = estimatedUnitsOfWork;
        unitsOfWorkDone = 0;
    }

    public int unitsOfWorkEstimated() {
        return unitsOfWork;
    }

    public int unitsOfWorkRemaining() {
        return unitsOfWork - unitsOfWorkDone;
    }

    public int unitsOfWorkCompleted() {
        return unitsOfWorkDone;
    }

    public void resetUnitsOfWorkCompleted() {
        this.unitsOfWorkDone = 0;
    }
    public void setUnitOfWOrk(String unit) {

    }

    public int incrementUnitsOfWorkCompleted(int units) {
        if (unitsOfWork > unitsOfWorkDone) {
            if ((unitsOfWork - unitsOfWorkDone) > units) {
                unitsOfWorkDone = unitsOfWorkDone + units;
                return 0;
            } else {
                int unitsConsumed = unitsOfWork - unitsOfWorkDone;
                unitsOfWorkDone = unitsOfWorkDone + unitsConsumed;
                return units - unitsConsumed;
            }
        }
        return units;
    }

    public int incrementUnitsOfWorkCompleted() {
        return incrementUnitsOfWorkCompleted(1);
    }


    public void getState() {

    }

    @Override
    public String toString() {
        return Integer.toString(unitsOfWorkEstimated());
    }
}
